import functools
import datetime


def timethis_my_again(label=None):
    label = '<no label>' if label is None else label

    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            t1 = datetime.datetime.now()
            result = func(*args, **kwargs)
            t2 = datetime.datetime.now()
            delta = t2 - t1
            print(f'{label} timethis_my_again: {func.__name__}: {delta}')
            return result
        return wrapper
    return decorator


if '__main__' == __name__:

    @timethis_my_again('***')
    def count_down(n: int):
        n_ = n
        t1 = datetime.datetime.now()
        while n > 0:
            n -= 1
        t2 = datetime.datetime.now()
        delta = t2 - t1
        print('count_down:', n_, delta)
        return delta

    print(count_down(1e6))

    @timethis_my_again()  # @timethis_my_again vs. @timethis_my_again()
    def count_down02(n: int):
        n_ = n
        t1 = datetime.datetime.now()
        while n > 0:
            n -= 1
        t2 = datetime.datetime.now()
        delta = t2 - t1
        print('countdown02:', n_, delta)
        return delta

    print(count_down02(1e5))

    def count_down03(n: int):
        n_ = n
        t1 = datetime.datetime.now()
        while n > 0:
            n -= 1
        t2 = datetime.datetime.now()
        delta = t2 - t1
        print('countdown03:', n_, delta)
        return delta

    count_down03 = timethis_my_again('@@@')(count_down03)
    print(count_down03(1e6))
